
CC = gcc
CFLAGS = -MMD -MP 
CFLAGS += $(DEFINE)      # make all DEFINE=-DDEBUG
SRCS  = $(wildcard *.S)
SRCS += $(wildcard *.c)
OBJS  = $(SRCS:.S=.o)
OBJS := $(OBJS:.c=.o)
DEPS  = $(SRCS:.S=.d)  
DEPS := $(DEPS:.c=.d)  

run: all
	cd ./test && make run
	@ if [ $? ];then\
		echo "test success\n";\
	  fi;

all: libsetjmp_hok.so 


libsetjmp_hok.so: $(OBJS)
	$(CC) -fPIC -shared $^ -o $@

-include $(DEPS)

%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@

%.o: %.S
	$(CC) $(CFLAGS) -c $< -o $@

clean:
	rm -f libsetjmp_hok.so $(OBJS) $(DEPS) && cd ./test && make clean

.PHONY: help
help:
	@echo "Usage: make <target> [option]"
	@echo "Targets:"
	@echo "  run    			: Compile the libsetjmp_hok.so and test"
	@echo "  all    			: Compile the libsetjmp_hok.so"
	@echo "  clean    			: Remove generated files"
	@echo "  help    			: Print this help"
	@echo "Option:"
	@echo "  DEFINE=-DDEBUG		: Compile with debug code"

